<?php


//CLASSE HELPER para Redirecionamento de página


class redirectorHelper {
    protected $paramenter = array();




    protected function go ($data) {
        header("Location: ".BASE."/$data");
    }
    
    public function setUrlParamenter($name, $value){
        $this->paramenter[$name] = $value;
        return $this;
    }
    
    public function getUrlParamenters(){
        $parms = "";
        foreach ($this->paramenter as $name => $value){
            
            $parms .= $name.'/'.$value.'/'; 
            return $parms;
        }
    }
    
    //redireciona para o controler
    //@param $controller
    public function goToController( $controller ){
        $this->go($controller.'/index/' . $this->getUrlParamenters() );
    }
    
    //vai para action atual do controller
    public function goToAction( $action ){
        $this->go( $this->getCurrentController().'/'. $action.'/'. $this->getUrlParamenters());
    }
    
    public function goToControllerAction( $controller , $action){
       $this->go( $controller.'/'. $action.'/'. $this->getUrlParamenters()); 
    }
    
    public function goToControllerAction2( $controller , $action , $url){
       $url = $this->getCurrentController().'/'.$this->getCurrentAction();
       $this->go( $controller.'/'. $action.'/'. $this->getUrlParamenters()); 
    }
    
    public function goToControllerAction_Array($controller , $action , $msg ){
         $this->go( $controller.'/'. $action.'/?msg='.$msg ); 
    }
    
    public function goToIndex(){
        $this->goToController('index');
    }
    
    public function goToUrl($url){
        header("Location: ".$url);
    } 
    
    public function getCurrentController(){
        global $start;
        return $start->_controller;
    }
    
     public function getCurrentAction(){
        global $start;
        return $start->_action;
    }
    
    
    /* Ir para página 404*/
    public function goToError(){
        unset($_SESSION["caminho"]);
         $action = $this->getCurrentAction();
        
        if ($action == "index_action"){
            $action = "";
            
            $caminho =BASE ."/". $this->getCurrentController();
            $_SESSION['caminho'] = $caminho;
        }
        else {
        $_SESSION['caminho'] =BASE ."/".$this->getCurrentController()."/".$action;
        }
        $this->goToControllerAction("index", "error");}
    
}
?>
